<template>
  <div>
    <el-form
      ref="searchForm"
      class="searchForm"
      :model="searchForm"
      label-width="50"
    >
      <el-row :gutter="12">
        <!--        合计24份  -->
        <el-col :span="8" :offset="1">
          <el-form-item prop="queryCondition.nickNameSml" label="姓名">
            <el-input v-model.trim="searchForm.queryCondition.nickNameSml">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6" :offset="3">
          <el-form-item prop="queryCondition.goldCoinMin" label="最小值">
            <el-input v-model="searchForm.queryCondition.goldCoinMin">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item prop="queryCondition.goldCoinMax" label="最大值">
            <el-input v-model="searchForm.queryCondition.goldCoinMax">
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="10" :offset="1">
          <el-form-item prop="queryCondition.professions" label="职业">
            <el-checkbox-group v-model="searchForm.queryCondition.professions">
              <el-checkbox
                v-for="e in professionTypes"
                :key="e.index"
                :label="e.value"
                >{{ e.text }}</el-checkbox
              >
            </el-checkbox-group>
          </el-form-item>
        </el-col>
      </el-row>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-edit"
          @click="queryByCondition(1)"
          >查询</el-button
        >
        <el-button
          type="warning"
          icon="el-icon-remove"
          @click="() => $refs.searchForm.resetFields()"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <el-row :gutter="12">
      <el-col :span="2" :offset="22">
        <!--      this.$on("queue",()=>{}) this.$off -->
        <insert-player @onSubmit="queryByCondition"> </insert-player>
        <!--        <insert-player v-on:afterSubmitSuccess="queryByCondition" ></insert-player>-->
      </el-col>
    </el-row>
    <!--
      {
      "playerId": 60,
      "playerCode": "8110768",
      "nickname": "李大章",
      "goldCoin": 78,
      "silverCoin": 90,
      "profession": "architect",
      "usernameFk": "2016207064",
      "version": 0
    },-->

    <el-table :data="results" stripe height="300">
      <el-table-column
        prop="playerCode"
        label="Code"
        width="80px"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="nickname"
        label="角色名称"
        align="center"
      ></el-table-column>

      <el-table-column label="职业" :formatter="professionFormat">
      </el-table-column>
<!--      <el-table-column prop="goldCoin" label="金币数量"></el-table-column>-->
<!--      <el-table-column prop="silverCoin" label="银币数量"></el-table-column>-->

      <el-table-column width="180px" fixed="left">
        <template slot-scope="props">
          <el-button
            class="el-button--mini"
            type="warning"
            icon="el-icon-edit"
            @click="openById(props.row.playerCode)"
            >编辑</el-button
          >
          <el-button
            class="el-button--mini"
            type="danger"
            icon="el-icon-edit"
            @click="deleteById(props.row.playerCode)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      :total="total"
      :page-size="searchForm.pageSize"
      :current-page="searchForm.pageNum"
      @current-change="queryByCondition"
      layout="total, prev, pager, next, jumper"
    ></el-pagination>
  </div>
</template>

<script>
import { mapState } from "vuex";
// import New from './components/New.vue';
import InsertPlayer from "@/components/InsertPlayer";
export default {
  name: "September",
  components: {
    InsertPlayer,
    // New,Old,
  },
  props: {
    sampleP: {
      type: Number,
      default: 0,
    },
  },
  data() {
    return {
      sampleD: "value",

      searchForm: {
        pageNum: 1,
        pageSize: 6,
        //该对象被渲染成为查询区域的form标签
        queryCondition: {
          goldCoinMax: null,
          goldCoinMin: null,
          nickNameSml: "",
          professions: [],
        },
      },
      //该对象被渲染成为table标签
      /*
      * {
      "playerId": 60,
      "playerCode": "8110768",
      "nickname": "李大章",
      "goldCoin": 78,
      "silverCoin": 90,
      "profession": "architect",
      "usernameFk": "2016207064",
      "version": 0
    },
      *
      * */
      results: [],
      //该对象被渲染成为分页器标签
      total: 0,

      /*
      *
      *   {
    "index": 0,
    "text": "建筑师",
    "value": "architect"
            },
      * */
  // professionTypes: [],
      visibility: false,
    };
  },
  computed: {

    ...mapState(["professionTypes"]),

    // sampleC() {
    //     return this.sampleD+'--';
    // }
  },
  created() {
    // this.$http({
    //   method: "get",
    //   url: "/ceto/common/professionTypes",
    // }).then(
    //   (res) => {
    //     this.professionTypes = res.data;
    //   },
    //   (error) => {
    //     console.log(" request error : " + error.response.status);
    //   }
    // );
  },
  mounted() {
    this.queryByCondition();
  },
  methods: {
    sampleM() {},
    queryByCondition(pageNum) {
      if (pageNum) this.searchForm.pageNum = pageNum;
      this.$http({
        method: "post",
        url: "/ceto/player/query",
        data: this.searchForm,
      }).then(
        (res) => {
          this.total = res.data.total;
          this.results = res.data.results;
          this.$message.warning(JSON.stringify(this.results));
        },
        (error) => {
          this.$message.warning("query mistake：" + error.response.status);
        }
      );
    },
    professionFormat(row) {
      // let k =  row.profession;
      let x = this.professionTypes.find((x) => x.value === row.profession);
      return x.text;
    },
  },
  watch: {
    // sampleC(newValue, oldValue) {
    //
    // }
  },
};
</script>

<!--<style scoped>-->
<style lang="scss" scoped>
.el-table {
  /*height: 250px;*/
}
</style>
